﻿using System.Configuration;
using Common.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Wicresoft.EKA.NRemedy;

namespace Wicresoft.EKA.ITSM.Web.WebPortal
{
    // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明，
    // 请访问 http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        private static readonly ILog logger = LogManager.GetCurrentClassLogger();
        protected void Application_Start()
        {
            logger.Info("Application_Start");

            //SecurityConfig.RegisterSecurity();

            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            //AuthConfig.RegisterAuth();

            IoCConfig.Register();

            var provider = new ARARLoginContextSerializerProvider();
            provider.ARServer = ConfigurationManager.AppSettings["ARServer"];
            provider.AdminName = ConfigurationManager.AppSettings["AdminName"];
            provider.AdminPassword = ConfigurationManager.AppSettings["AdminPassword"];

            GlobalSettings.SetCharacterEncoding("UTF8");
            NRemeyWebGlobal.Provider = provider;

            // DataAnnotationsModelValidatorProvider.RegisterAdapterFactory(typeof(RequiredAttribute), (m, c, a) => new MyRequiredAttributeAdapter(m, c, (RequiredAttribute)a));

        }

        protected void Application_End()
        {
            logger.Info("Application_End");

        }

        protected void Application_Error(Object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError().GetBaseException();

            logger.Error(sender.GetType().ToString() + "   " + e.ToString() + "   " + e.GetType() + "  " + ex.Message);
        }
    }
}